package com.hex.liyue.usermodule.presenter;

import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.usermodule.bean.AddressResultBean;

/**
 * Created by WJ on 2016/6/21.
 */
public class AddressPresenter {
    private IAddressView iAddressView;

    public AddressPresenter(IAddressView iAddressView) {
        this.iAddressView = iAddressView;
    }

    /**
     * 获取我的所有地址列表
     */
    public void requestAddressList() {
        iAddressView.showLod("加载中...");
        HttpManager.getInstance().getAddressList(UserManager.getUserId(), new ResponseListener<AddressResultBean>() {
            @Override
            public void onSuccess(AddressResultBean addressResultBean) {
                iAddressView.closeLod();
                iAddressView.setAdapter(addressResultBean);
            }

            @Override
            public void onFailure(String responseresult) {
                iAddressView.showT(responseresult);
                iAddressView.closeLod();
            }
        });
    }

    /**
     * 删除我的地址
     *
     * @param delivery_id
     */
    public void requestDelete(String delivery_id) {
        HttpManager.getInstance().deleteAddress(UserManager.getUserId(),delivery_id, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                requestAddressList();
            }

            @Override
            public void onFailure(String responseresult) {
                iAddressView.showT(responseresult);
            }
        });
    }

    /**
     * 设为默认
     *
     * @param delivery_id
     */
    public void requetsUpdateFirst(String delivery_id) {
        HttpManager.getInstance().updateAddressFirst(UserManager.getUserId(),delivery_id, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                requestAddressList();
            }

            @Override
            public void onFailure(String responseresult) {
                iAddressView.showT(responseresult);
            }
        });
    }
}
